package com.power.project.controller;


import cn.hutool.core.lang.tree.Tree;
import com.power.common.domain.ResponseDTO;
import com.power.project.api.IWw_departFeign;
import com.power.project.model.Ww_depart;
import com.power.project.model.Ww_depart_user;
import com.power.project.model.Ww_user;
import com.power.project.model.bo.DepartLeaderSetBO;
import com.power.project.model.bo.DepartSaveuserBO;
import com.power.project.model.bo.DepartmentSaveBO;
import com.power.project.model.bo.DepartmentSortBO;
import com.power.project.model.vo.DepartLeaderForSetVO;
import com.power.project.service.Ww_departService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
 * 企业微信部门信息控制器
 */

@RestController
@Api(value = "部门管理", tags = {"部门管理"})
public class Ww_departController implements IWw_departFeign {

    @Resource
    private Ww_departService ww_departService;


    @Override
    public ResponseDTO<List<Tree<String>>> tree(String tenantId) {
        return ResponseDTO.succData(ww_departService.tree(tenantId));
    }

    @Override
    public ResponseDTO<List<Tree<String>>> departUserTree(String tenantId) {
        return ResponseDTO.succData(ww_departService.departUserTree(tenantId));
    }


    @Override
    @ApiOperation("删除企业微信部门信息")
    public ResponseDTO<Void> delete(String departId) {
        ww_departService.removeById(departId);
        return ResponseDTO.succ();
    }

    @Override
    @ApiOperation("新增部门信息")
    public ResponseDTO<Void> save(DepartmentSaveBO saveBO) {
        Assert.notNull(saveBO.getParentId(),"父部门id不能为空");
        Assert.notNull(saveBO.getTenantId(),"租户id不能为空");
        Assert.hasLength(saveBO.getTenantId(),"租户id不能为空");
        ww_departService.save(saveBO);
        return ResponseDTO.succ();
    }

    @Override
    public ResponseDTO<Void> rename(DepartmentSaveBO saveBO) {
        Assert.notNull(saveBO.getDepartId(),"部门id不能为空");
        ww_departService.rename(saveBO);
        return ResponseDTO.succ();
    }

    @Override
    public ResponseDTO<Void> sort(DepartmentSortBO sortBO) {
        ww_departService.sort(sortBO);
        return ResponseDTO.succ();
    }

    @Override
    public ResponseDTO<List<Ww_depart>> querychildrn(String parentId) {
        return ResponseDTO.succData(ww_departService.getByParentId(parentId));
    }

    @Override
    public ResponseDTO<Void> departmentUsers(@Valid DepartSaveuserBO saveuserBO) {
        ww_departService.saveUsers(saveuserBO);
        return ResponseDTO.succ();
    }

    @Override
    public ResponseDTO<List<Ww_user>> queryUsers(String departId) {
        return ResponseDTO.succData(ww_departService.queryUsers(departId));
    }

    @Override
    public ResponseDTO<List<DepartLeaderForSetVO>> leaderList(String departId) {
        return ResponseDTO.succData(ww_departService.leaderList(departId));
    }

    @Override
    public ResponseDTO<Void> setLeader(DepartLeaderSetBO setBO) {
        ww_departService.setLeader(setBO);
        return ResponseDTO.succ();
    }
}
